package com.example.asus_pc.myshop.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.asus_pc.myshop.R;
import com.example.asus_pc.myshop.bean.VegaBean;

import java.util.ArrayList;
import java.util.List;

public class ShowVegaAdatpter extends RecyclerView.Adapter<ShowVegaAdatpter.ItemViewHolder> {

    private LayoutInflater mInflater;
    Context context;


    List<VegaBean> datas;

    public ShowVegaAdatpter(Context context) {
        this.context = context;
        this.mInflater = LayoutInflater.from(context);
        datas = new ArrayList<>();
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = mInflater.inflate(R.layout.item_show_vega, null);

        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ItemViewHolder holder, final int i) {
        holder.tvNO.setVisibility(View.VISIBLE);
        holder.tvVeganame.setVisibility(View.VISIBLE);
        holder.tvTotalPrice.setVisibility(View.VISIBLE);
        holder.tvSplitPrice.setVisibility(View.VISIBLE);

        holder.tvNO.setText(i + 1 + "");
        holder.tvVeganame.setText(datas.get(i).getVegaName());
        holder.tvTotalPrice.setText(datas.get(i).getTotalPrice() == 0 ? "" : datas.get(i).getTotalPrice() + "");
        holder.tvSplitPrice.setText(datas.get(i).getSplitPrice() == 0 ? "" : datas.get(i).getSplitPrice() + "");

        Log.e("bindHolder" + i, "totalPrice" + datas.get(i).getTotalPrice() + "" + datas.get(i).getSplitPrice());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    public void setDatas(List<VegaBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder {
        TextView tvNO;
        TextView tvVeganame;
        TextView tvTotalPrice;
        TextView tvSplitPrice;


        public ItemViewHolder(View itemView) {
            super(itemView);
            tvNO = (TextView) itemView.findViewById(R.id.tv_order_number);
            tvVeganame = (TextView) itemView.findViewById(R.id.tv_vega_name);
            tvTotalPrice = (TextView) itemView.findViewById(R.id.tv_total_price);
            tvSplitPrice = (TextView) itemView.findViewById(R.id.tv_splite_price);

        }

    }


}
